
<?
    // Up file to flickr
    function upfile_flick($url,$title,$description=''){
        $api_key    = '2e4e72a03aa4db503bfe128e4b4b20e6';
        $api_secret = '7a7efe62bce5d84e';
        $flickr = new phpFlickr($api_key,$api_secret, true);
        $result = $flickr->sync_upload($url, $title, $description, "$title,Tin tức cập nhật, Tin tức online 24h,vnupdate.net");
        $response = json_decode(file_get_contents('http://api.flickr.com/services/rest/?method=flickr.photos.getInfo&api_key='.$api_key.'&photo_id='.$result.'&format=json&nojsoncallback=1'),0);
        return 'farm'.$response->photo->farm.'.staticflickr.com/'.$response->photo->server.'/'.$response->photo->id.'_'.$response->photo->secret.'.'.$response->photo->originalformat;
    }
    function del_more($description){
        $description = str_replace('&nbsp;','',$description);
        return $description;
    }
    function remove_ext($string){
        $name   = explode('.',$string);
        return  $name;    
    }
	function cut_string_url($link){
        if($link == '' || !isset($link)){
            return Null;
        }else{
            $link = explode("/",$link);
        }
        $total = count($link);
        $linkl = $link[$total-1];
        return $linkl;
    }
    function generate_name($filename){
        $name = "";
        for($i=0; $i<3; $i++){
            $name .= chr(rand(97,122));
        }
        $today= getdate();
        $name.= $today[0];
        $ext    = substr($filename, (strrpos($filename, ".") + 1));
        return $name . "." . $ext;
    }
    function cut_page_url($links,$num_page,$domain){
        if($domain == 'dantri.com.vn'){
            $link = str_replace(".htm", '/',$links);
            $link = $link.'trang-'.$num_page.'.htm';
        }
        if($domain == 'kenh14.vn'){
            $link = str_replace(".chn", '/',$links);
            $link = $link.'trang-'.$num_page.'.chn';
        }
        if($domain == 'genk.vn'){
            $link = str_replace(".chn", '/',$links);
            $link = $link.'page-'.$num_page.'.chn';
        }
        if($domain == 'ngoisao.net'){
            $link = $links.'?p='.$num_page;
        }
        if($domain == 'marketing.24h.com.vn'){
            $link = $links.'page/'.$num_page.'/';
        }
        if($domain == 'caia.vn'){
            $link = $links.'page/'.$num_page.'/';
        }
        if($domain == "chienluocmarketing.edu.vn"){
           $link = $links;
        }
        return $link;
    }
    function CURLCONTENT($domain,$link_details){
        $file = $_SERVER["DOCUMENT_ROOT"].'\getNews\cookie.txt';
        $ch = curl_init(); 
        curl_setopt ($ch, CURLOPT_URL, "$domain"); 
        curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
        curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); 
        curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
        curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0); 
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt ($ch, CURLOPT_COOKIESESSION, 1);
        curl_setopt ($ch, CURLOPT_COOKIEJAR, "");
        curl_setopt($ch, CURLOPT_REFERER, "");
        //curl_setopt ($ch, CURLOPT_REFERER, $refere); 
        curl_setopt ($ch, CURLOPT_COOKIEFILE, $file);
        //curl_setopt ($ch, CURLOPT_REFERER, $refere); 
        curl_setopt ($ch, CURLOPT_POSTFIELDS, ''); 
        curl_setopt ($ch, CURLOPT_POST, 1); 
        $result = curl_exec($ch); 
        return $result;      
    }
    function POSTDATAUP($postdata){
        $URL_API = 'http://vnupdate.net/getNews/data_api.php';
        $file = $_SERVER["DOCUMENT_ROOT"].'\getNews\cookie.txt';
        $ch = curl_init(); 
        curl_setopt ($ch, CURLOPT_URL, $URL_API); 
        curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
        curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); 
        curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
        curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0); 
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt ($ch, CURLOPT_COOKIESESSION, 1);
        curl_setopt ($ch, CURLOPT_COOKIEJAR, "vnupdate.net");
        curl_setopt($ch, CURLOPT_REFERER, "http://www.vnupdate.net");
        curl_setopt ($ch, CURLOPT_COOKIEFILE, $file);
        //curl_setopt ($ch, CURLOPT_REFERER, $refere); 
        curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
        curl_setopt ($ch, CURLOPT_POST, 1); 
        $result = curl_exec($ch); 
        return $result;    
    }
    function POSTDATAUPEDIT($postdata){
        $URL_EDIT_DATA = 'http://vnupdate.net/getNews/edit_data_api.php';
        $file = $_SERVER["DOCUMENT_ROOT"].'\getNews\cookie_edit.txt';
        $ch = curl_init(); 
        curl_setopt ($ch, CURLOPT_URL, $URL_EDIT_DATA); 
        curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
        curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); 
        curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
        curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0); 
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt ($ch, CURLOPT_COOKIESESSION, 1);
        curl_setopt ($ch, CURLOPT_COOKIEJAR, "vnupdate.net");
        curl_setopt($ch, CURLOPT_REFERER, "http://www.vnupdate.net");
        curl_setopt ($ch, CURLOPT_COOKIEFILE, $file);
        //curl_setopt ($ch, CURLOPT_REFERER, $refere); 
        curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
        curl_setopt ($ch, CURLOPT_POST, 1); 
        $result = curl_exec($ch); 
        return $result;    
    }
?>